//
//  YMChatManager.h
//  YMIM
//
//  Created by reyzhang on 2022/3/18.
//

#import <Foundation/Foundation.h>
#import "YMCommonDefs.h"
#import "YMUserInfo.h"
#import "YMGroupInfo.h"
#import "YMConversation.h"

NS_ASSUME_NONNULL_BEGIN


/**
 * IM 聊天信息管理器， 管理会话的获取，加入，删除、消息的发送、用户资料的更新
 */
@class YMMessage;
@interface YMChatManager : NSObject


/**
 * 发送消息
 *
 * @param message 消息数据模型
 *
 * @param completionBlock 消息发送回调
 */
- (void)sendMessage:(YMMessage *)message completion:(void(^)(YMMessage *message, YMErrorCode code))completionBlock;


/**
 * 用户信息变更，更新用户持久化信息
 *
 * @param completionBlock 更新用户信息回调
 */
- (void)updateUserInfo:(YMUserInfo *)userInfo completion:(void(^)(YMUserInfo *userInfo, YMErrorCode code))completionBlock;


/**
 * 加入单聊
 *
 * @param tid 目标用户的userId （唯一身份标识）
 *
 * @param label 会话分组标签，可根据分组过滤会话
 */
- (void)joinPrivateChatWithTargetId:(NSString *)tid
                              label:(NSInteger)label
                         completion:(void(^)(YMGroupInfo *groupInfo, YMErrorCode code))completionBlock;
/**
 * 不区分label 会话标签
 */
- (void)joinPrivateChatWithTargetId:(NSString *)tid
                         completion:(void(^)(YMGroupInfo *groupInfo,YMErrorCode code))completionBlock;



/**
 * 获取会话列表
 *
 * @param conversationTypeList 会话类型的数组，需要将 YMConversationType 转为 NSNumber 构建 Array
 *
 * @param label 标签， 分组会话
 */
- (void)getConversationList:(NSArray<NSNumber*> *)conversationTypeList
                      count:(NSInteger)count
                      label:(NSInteger)label
            completionBlock:(void(^)(NSArray<YMConversation *> *dataSource, YMErrorCode code))completionBlock;

/**
 * 不区分label 会话标签
 */
- (void)getConversationList:(NSArray<NSNumber*> *)conversationTypeList
                      count:(NSInteger)count
            completionBlock:(void(^)(NSArray<YMConversation *> *dataSource, YMErrorCode code))completionBlock;





/**
 * 删除会话
 *
 * @param groupId 组/会话 id
 *
 * @param completionBlock 执行结果回调
 */
- (void)removeConversationWithTargetId:(NSString *)groupId
                            completion:(void(^)(YMErrorCode code))completionBlock;


/**
 * 获取会话详情
 *
 * @param groupId 组/会话 id
 *
 * @param completionBlock 执行结果回调
 */
- (void)getConversationWithTargetId:(NSString *)groupId
                         completion:(void(^)(YMConversation *conversation,YMErrorCode code))completionBlock;




/**
 * 获取某个会话下的消息
 *
 * @param groupId 组/会话唯一标识
 *
 * @param pageIndex 分页数据索引
 *
 * @param pageSize 每页显示的条数
 *
 * @param completionBlock 结果回调
 */
- (void)getHistoryMessageWithTargetId:(NSString *)groupId
                                 page:(NSInteger)pageIndex
                             pageSize:(NSInteger)pageSize
                           completion:(void(^)(NSArray<YMMessageInfo *> *dataSource, NSInteger totalPage))completionBlock;



/**
 * 置顶会话
 *
 * @param groupId 组/会话唯一标识
 *
 * @param completionBlock 结果回调
 */
- (void)topConversationWithTargetId:(NSString *)groupId
                         completion:(void(^)(YMErrorCode code))completionBlock;



/**
 * 会话消息免打扰
 *
 * @param groupId 组/会话唯一标识
 *
 * @param completionBlock 结果回调
 */
- (void)doNotDisturbConversationWithTargetId:(NSString *)groupId
                                  completion:(void(^)(YMErrorCode code))completionBlock;



/**
 * 获取所有未读消息数量
 */
- (void)unreadMessageCountWithCompletion:(void(^)(YMErrorCode code))completionBlock;

/**
 * 搜索用户
 *
 * @param keyword 关键字
 */
- (void)searchUserListWithKeyword:(NSString *)keyword
                       completion:(void(^)(NSArray<YMUserInfo *> *userList,YMErrorCode code))completionBlock;



/**
 * 清空聊天消息
 *
 * @param groupId 组/会话唯一标识
 */
- (void)clearMessageWithTargetId:(NSString *)groupId
                      completion:(void(^)(YMErrorCode code))completionBlock;


@end

NS_ASSUME_NONNULL_END
